angular.module('mvcApp.register', [
    'ngRoute',
    'ngResource'
]).config(['$routeProvider', function($routeProvider) {
    $routeProvider
        .when('/register', {
            templateUrl: 'static/views/register.html',
            controller: 'RegisterCtrl'
        });
}]).controller('RegisterCtrl', ['$scope', '$http', 'User',
    function ($scope, $http, User) {
        $scope.register = function (username, password, isShopOwner) {
            if(!username || !password) {
                alert("用户名密码不可为空");
                return;
            }
            User.register(username, password, isShopOwner)
                .then(function(data) {
                    alert("注册成功");
                    window.location.href = '#/login';
                }).catch(function(e) {
                    alert(e);
                });
        };
    }]);